package dfsketches.gr3d;

public abstract class Spline {

	public Spline(SplinePoint[] points, boolean loop) {
		pts = points;
		looped = loop;
	}
	
	public Spline(SplinePoint[] points) {
		this(points, false);
	}

	public abstract Matrix3D getTransformation(float time);
	public abstract Matrix3D getTransformation(float time, Matrix3D output);
	
	public boolean hasLoop() {
		return looped;
	}
	
	public float getEndTime() {
		return pts[pts.length - 1].time;
	}

	protected int binSearch(float time) {
		int start = 0;
		int end = pts.length - 1;
		int med;
		while (start + 1 < end) {
			med = (start + end) / 2;
			if (time > pts[med].time) {
				start = med;
			} else {
				end = med;
			}
		}
		return start;
	}
	
	protected SplinePoint[] pts;
	protected boolean looped;
}
